Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error reporting #2376

Merged
merged 3 commits into from
Feb 1, 2022
Merged

Improve error reporting #2376

merged 3 commits into from
Feb 1, 2022

Conversation

jackkoenig
Copy link
Contributor

@jackkoenig jackkoenig commented Feb 1, 2022

Inspired by @oharboe's comments here: ucb-bar/chiseltest#501 (comment).

This gives a little bit of refinement to error reporting.

  1. Making sure that our stack trace trimming doesn't accidentally add stack traces to exceptions that don't have them otherwise.
  2. Providing a name to the exception thrown by collected errors so that it doesn't have $$anon$1 in the error message
  3. Add --throw-on-first-error to give users the option to throw exceptions instead of aggregating recoverable errors

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you state the API impact?
  • Did you specify the code generation impact?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • code cleanup

API Impact

This changes how errors are reported to make them a little more clear

Backend Code Generation Impact

No impact

Desired Merge Strategy

  • Squash

Release Notes

Improve recoverable error reporting and add --throw-on-first-error for throwing exceptions instead of aggregating recoverable errors.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels?
  • Did you mark the proper milestone (Bug fix: 3.4.x, [small] API extension: 3.5.x, API modification or big change: 3.6.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you mark as Please Merge?

This prevents us from accidentally giving stack traces to exceptions
that don't have them and giving misleading messages telling users to use
--full-stacktrace when it won't actually do anything.

Also deprecate ChiselException.chiselStackTrace which is no longer being
used anywhere in this codebase.
New chisel3.internal.Errors replaces old anonymous class that would show
up as chisel3.internal.ErrorLog$$anon$1 in error messages.
Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Nice usage of info in the tests.

@@ -61,6 +61,24 @@ case object PrintFullStackTraceAnnotation

}

/** On recoverable errors, this will cause Chisel to throw an exception instead of continuing.
*/
case object ThrowOnFirstErrorAnnotation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this expected to be used as an annotation? If not, then this can be made private[chisel3.stage].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be needed by chiseltest which only exposes Annotations and not arguments, but good suggestion in general

@@ -207,4 +241,53 @@ class ChiselStageSpec extends AnyFlatSpec with Matchers with Utils {
exception.getStackTrace.mkString("\n") should include("java")
}

it should "NOT add a stack trace to an exception with no stack trace" in {
val exception = intercept[java.lang.Exception] {
(new ChiselStage).emitChirrtl(new UserExceptionNoStackTrace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: only elaborate should be needed here (though there is no cost to using emitChirrtl.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that class ChiselStage doesn't have elaborate 🤦‍♂️

This tells Chisel not to aggregate recoverable errors but instead to
throw an exception on the first one. This gives a stack trace for users
who need it for debugging.
@jackkoenig jackkoenig force-pushed the improve-error-reporting branch from 2abff61 to fc9f401 Compare February 1, 2022 17:33
@jackkoenig jackkoenig added the Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI. label Feb 1, 2022
@mergify mergify bot merged commit ff2e9c9 into master Feb 1, 2022
@mergify mergify bot deleted the improve-error-reporting branch February 1, 2022 18:19
mergify bot pushed a commit that referenced this pull request Feb 1, 2022
* Do not trim stack traces of exceptions with no stack trace

This prevents us from accidentally giving stack traces to exceptions
that don't have them and giving misleading messages telling users to use
--full-stacktrace when it won't actually do anything.

Also deprecate ChiselException.chiselStackTrace which is no longer being
used anywhere in this codebase.

* Add exception class for multiple-errors reported

New chisel3.internal.Errors replaces old anonymous class that would show
up as chisel3.internal.ErrorLog$$anon$1 in error messages.

* Add new option --throw-on-first-error

This tells Chisel not to aggregate recoverable errors but instead to
throw an exception on the first one. This gives a stack trace for users
who need it for debugging.

(cherry picked from commit ff2e9c9)
@mergify mergify bot added the Backported This PR has been backported label Feb 1, 2022
mergify bot added a commit that referenced this pull request Feb 1, 2022
* Improve error reporting (#2376)

* Do not trim stack traces of exceptions with no stack trace

This prevents us from accidentally giving stack traces to exceptions
that don't have them and giving misleading messages telling users to use
--full-stacktrace when it won't actually do anything.

Also deprecate ChiselException.chiselStackTrace which is no longer being
used anywhere in this codebase.

* Add exception class for multiple-errors reported

New chisel3.internal.Errors replaces old anonymous class that would show
up as chisel3.internal.ErrorLog$$anon$1 in error messages.

* Add new option --throw-on-first-error

This tells Chisel not to aggregate recoverable errors but instead to
throw an exception on the first one. This gives a stack trace for users
who need it for debugging.

(cherry picked from commit ff2e9c9)

* Waive MiMa false positives

The waived change is to a package private constructor.

Co-authored-by: Jack Koenig <koenig@sifive.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
jackkoenig pushed a commit that referenced this pull request Feb 28, 2023
…#2376)

* Demonstrate a couple failing cases

* Have TopWiring ignore unnamed declarations as potential sources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported This PR has been backported Please Merge Accepted PRs that are ready to be merged. Useful when waiting on CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants